package com.sta.staff.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sta.staff.bean.Result;
import com.sta.staff.mapper.SalaryMapper;
import com.sta.staff.mapper.UsersMapper;
import com.sta.staff.pojo.Salary;
import com.sta.staff.pojo.Users;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SalaryService {
    @Autowired
    private SalaryMapper salaryMapper;
    @Autowired
    private UsersMapper usersMapper;
    //查询所有员工工资
    public List<Salary> findAllSalary(){
        List<Salary> allSalary = salaryMapper.findAllSalary();

        return allSalary;
    }
    //查询指定员工工资
    public List<Salary> findLikeSalary(String search){
        List<Salary> allSalary = salaryMapper.findLikeSalary(search);

        return allSalary;
    }

    //给员工添加新工资
    public void add(Integer uid,Salary salary){
        salaryMapper.insert(salary);
        salaryMapper.addUsersSalary(uid,salary.getSid());

    }

    //判断新增工资数据是否为空
    public Result judge(String username,Salary salary){
        if (username==null || username.length()<1){
            return new Result(false,"工号不能为空");
        }

        if (salary.getTime()==null || salary.getTime().length()<1){
            return new Result(false,"时间不能为空");
        }

        return new Result(true,"添加成功");
    }
    //判断修改工资数据是否为空
    public Result judge2(Salary salary){

        if (salary.getTime()==null || salary.getTime().length()<1){
            return new Result(false,"时间不能为空");
        }

        return new Result(true,"添加成功");
    }

    //删除员工工资
    public void delete(Integer sid){
        salaryMapper.deleteUsersSalary(sid);
        salaryMapper.deleteById(sid);
    }

    //根据id将工资回显到修改页面
    public Salary findBySid(Integer sid){
        return salaryMapper.selectById(sid);
    }

    //修改员工工资
    public void update(Salary salary){
        salaryMapper.updateById(salary);
    }

    //查看自己工资
    public List<Users> findMySalary(Integer uid){
        List<Users> mySalary = usersMapper.findMySalary(uid);
        return mySalary;
    }

}
